<html>
<head><meta charset="utf-8"><title>black_box dejavu · general · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/index.html">general</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/black_box.20dejavu.html">black_box dejavu</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="158394793"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/black_box%20dejavu/near/158394793" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/black_box.20dejavu.html#158394793">(Feb 12 2019 at 22:43)</a>:</h4>
<p><span class="user-mention" data-user-id="124289">@rkruppe</span> <a href="http://lists.llvm.org/pipermail/llvm-dev/2015-November/091968.html" target="_blank" title="http://lists.llvm.org/pipermail/llvm-dev/2015-November/091968.html">http://lists.llvm.org/pipermail/llvm-dev/2015-November/091968.html</a></p>



<a name="158394844"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/black_box%20dejavu/near/158394844" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/black_box.20dejavu.html#158394844">(Feb 12 2019 at 22:44)</a>:</h4>
<p>i just found that, not sure if you have seen it</p>



<a name="158394853"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/black_box%20dejavu/near/158394853" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Hanna Kruppe <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/black_box.20dejavu.html#158394853">(Feb 12 2019 at 22:44)</a>:</h4>
<p>Oh gods I recognize that name</p>



<a name="158395426"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/black_box%20dejavu/near/158395426" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/black_box.20dejavu.html#158395426">(Feb 12 2019 at 22:52)</a>:</h4>
<p><span class="user-mention" data-user-id="124289">@rkruppe</span> after reading all that, i have some thoughts</p>



<a name="158395444"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/black_box%20dejavu/near/158395444" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/black_box.20dejavu.html#158395444">(Feb 12 2019 at 22:53)</a>:</h4>
<p>first, we don't want to say which optimizations <code>black_box</code> inhibits</p>



<a name="158395461"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/black_box%20dejavu/near/158395461" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/black_box.20dejavu.html#158395461">(Feb 12 2019 at 22:53)</a>:</h4>
<p>that would tie <code>black_box</code> definition to some optimization pipeline</p>



<a name="158395569"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/black_box%20dejavu/near/158395569" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/black_box.20dejavu.html#158395569">(Feb 12 2019 at 22:54)</a>:</h4>
<p>second, it feels like we want <code>black_box</code> to "inhibit optimizations" but while still generating optimized code, this is a problem</p>



<a name="158395674"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/black_box%20dejavu/near/158395674" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/black_box.20dejavu.html#158395674">(Feb 12 2019 at 22:56)</a>:</h4>
<p>third, the identity function is not what we want, because we don't want <code>back_box(T) -&gt; T</code> to return the same <code>T</code> that it takes as an argument</p>



<a name="158395709"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/black_box%20dejavu/near/158395709" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/black_box.20dejavu.html#158395709">(Feb 12 2019 at 22:57)</a>:</h4>
<p>i think that what we want is for the code around <code>black_box(T) -&gt; T</code> to be optimized as if <code>black_box</code> performs a volatile write of its argument to global memory, and then performs a volatile read of global memory, returning that result</p>



<a name="158395721"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/black_box%20dejavu/near/158395721" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/black_box.20dejavu.html#158395721">(Feb 12 2019 at 22:57)</a>:</h4>
<p>at the same time, we don't want any machine code to be generated to perform those reads and writes</p>



<a name="158395862"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/black_box%20dejavu/near/158395862" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/black_box.20dejavu.html#158395862">(Feb 12 2019 at 22:59)</a>:</h4>
<p>so that's basically what the <code>asm!</code> macros do</p>



<a name="158395975"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/black_box%20dejavu/near/158395975" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Hanna Kruppe <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/black_box.20dejavu.html#158395975">(Feb 12 2019 at 23:00)</a>:</h4>
<p>I am very wary of defining an operation as "pretend it does these operations, but don't actually codegen it that way". For starters, that doesn't indicate what the right <em>semantics</em> are, and the semantics are ultimately what drives development of optimizations (and lots of other stuff!). I also do not know how to implement that other than carrying this operation not just through all of IR but also practically all of the backend. That's a lot of real estate.</p>



<a name="158396150"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/black_box%20dejavu/near/158396150" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/black_box.20dejavu.html#158396150">(Feb 12 2019 at 23:02)</a>:</h4>
<p>right now we implement it with <code>asm!</code> telling LLVM that we read some memory with side-effects, but emitting no instructions within the assembly block, generating no machine code</p>



<a name="158396187"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/black_box%20dejavu/near/158396187" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/black_box.20dejavu.html#158396187">(Feb 12 2019 at 23:03)</a>:</h4>
<p>that might well be the right way to implement these semantics in LLVM</p>



<a name="158396268"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/black_box%20dejavu/near/158396268" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Hanna Kruppe <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/black_box.20dejavu.html#158396268">(Feb 12 2019 at 23:04)</a>:</h4>
<p>I may be misunderstanding what you're targeting here. Is this wording supposed to go into the user facing docs? Is that supposed to provide any tangible guarantees to users?</p>



<a name="158396522"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/black_box%20dejavu/near/158396522" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/black_box.20dejavu.html#158396522">(Feb 12 2019 at 23:08)</a>:</h4>
<p>The thing is that the guarantees that we provide to users cannot be used for optimizations</p>



<a name="158396585"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/black_box%20dejavu/near/158396585" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/black_box.20dejavu.html#158396585">(Feb 12 2019 at 23:09)</a>:</h4>
<p>To users we want to say <code>black_box</code> returns its argument and has no effects (it is a <code>nop</code>).<br>
To the optimizer we want to say: <code>black_box</code> performs a volatile write of its argument to global memory, and a volatile read of some other value from global memory, and returns that.</p>



<a name="158396647"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/black_box%20dejavu/near/158396647" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/black_box.20dejavu.html#158396647">(Feb 12 2019 at 23:10)</a>:</h4>
<p>I don't know how a specification could specify both, they sound incompatible to me.</p>



<a name="158396773"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/black_box%20dejavu/near/158396773" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Hanna Kruppe <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/black_box.20dejavu.html#158396773">(Feb 12 2019 at 23:12)</a>:</h4>
<p>It's true that this kind of function is inherently self-contradicting to a degree, but I don't see the actual problem with what is the status quo implementation and in the RFC text right now?</p>



<a name="158396791"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/black_box%20dejavu/near/158396791" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/black_box.20dejavu.html#158396791">(Feb 12 2019 at 23:12)</a>:</h4>
<p>The RFC says that <code>black_box</code> is a <code>nop</code>, and that it might inhebit some optimizations as a quality of implementation issue.</p>



<a name="158396819"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/black_box%20dejavu/near/158396819" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Hanna Kruppe <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/black_box.20dejavu.html#158396819">(Feb 12 2019 at 23:13)</a>:</h4>
<p>Yes. And in practice we implement it as inline asm, which as you said seems to do something roughly sensible. What more is needed?</p>



<a name="158396828"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/black_box%20dejavu/near/158396828" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/black_box.20dejavu.html#158396828">(Feb 12 2019 at 23:13)</a>:</h4>
<p>Remove the quality of implementation.</p>



<a name="158396893"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/black_box%20dejavu/near/158396893" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Hanna Kruppe <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/black_box.20dejavu.html#158396893">(Feb 12 2019 at 23:14)</a>:</h4>
<p>I see no remotely reasonable way to do that, for many reasons some of which you stated earlier. Nor do I see any need for that for the benchmarking use case.</p>



<a name="158396895"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/black_box%20dejavu/near/158396895" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/black_box.20dejavu.html#158396895">(Feb 12 2019 at 23:14)</a>:</h4>
<p>We have to say that <code>black_box</code> is a <code>nop</code>, but for the purposes of code generation, it is treated as an unknown function that performs a volatile write of its argument to global memory, and returns some value that is volatile read from global memory, except that when all optimizations are over, it is replaced by a nop.</p>



<a name="158396907"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/black_box%20dejavu/near/158396907" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Hanna Kruppe <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/black_box.20dejavu.html#158396907">(Feb 12 2019 at 23:14)</a>:</h4>
<p>Why do we "have to say" that?</p>



<a name="158396958"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/black_box%20dejavu/near/158396958" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/black_box.20dejavu.html#158396958">(Feb 12 2019 at 23:15)</a>:</h4>
<p>We'd have to say something like that if we wanted to more precisely guarantee how optimizations are inhibited by the function</p>



<a name="158397013"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/black_box%20dejavu/near/158397013" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/black_box.20dejavu.html#158397013">(Feb 12 2019 at 23:16)</a>:</h4>
<p>That would be a way of doing that.</p>



<a name="158397051"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/black_box%20dejavu/near/158397051" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/black_box.20dejavu.html#158397051">(Feb 12 2019 at 23:17)</a>:</h4>
<p>I'd guess the question is whether we want people to be able to rely on black_box being optimized in a certain way or not.</p>



<a name="158397057"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/black_box%20dejavu/near/158397057" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/black_box.20dejavu.html#158397057">(Feb 12 2019 at 23:17)</a>:</h4>
<p>the RFC says that this is not what we want</p>



<a name="158397063"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/black_box%20dejavu/near/158397063" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/black_box.20dejavu.html#158397063">(Feb 12 2019 at 23:17)</a>:</h4>
<p>but some want this</p>



<a name="158397070"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/black_box%20dejavu/near/158397070" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/black_box.20dejavu.html#158397070">(Feb 12 2019 at 23:17)</a>:</h4>
<p>not necessary for benchmarks, but would be nice to have</p>



<a name="158397290"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/black_box%20dejavu/near/158397290" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Hanna Kruppe <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/black_box.20dejavu.html#158397290">(Feb 12 2019 at 23:21)</a>:</h4>
<p>I think a lot of people have some idea in their head that they could do a certain thing if they could just shut up the pesky optimizer, but I think a lot of these fall under the category as &lt;<a href="https://twitter.com/johnregehr/status/1074712581749657600" target="_blank" title="https://twitter.com/johnregehr/status/1074712581749657600">https://twitter.com/johnregehr/status/1074712581749657600</a>&gt; and the ones that can be salvaged would be <em>far</em> better served by understanding what it is they actually want in terms of the language semantics (not the optimizer) and finding or adding a way to express that.</p>
<div class="inline-preview-twitter"><div class="twitter-tweet"><a href="https://twitter.com/johnregehr/status/1074712581749657600" target="_blank"><img class="twitter-avatar" src="https://pbs.twimg.com/profile_images/983125761522417665/rK8etQKP_normal.jpg"></a><p>true fact: if you leave a comment explaining that you understand you're doing something undefined, the compiler has to do what you mean <a href="https://t.co/or73tx8dOY" target="_blank" title="https://t.co/or73tx8dOY">https://twitter.com/volatile_void/status/1074710332722069504</a></p><span>- John Regehr (@johnregehr)</span></div></div>



<a name="158397351"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/black_box%20dejavu/near/158397351" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Hanna Kruppe <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/black_box.20dejavu.html#158397351">(Feb 12 2019 at 23:22)</a>:</h4>
<p>See also Ralf's excellent comment on the RFC PR</p>



<a name="158397400"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/black_box%20dejavu/near/158397400" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Hanna Kruppe <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/black_box.20dejavu.html#158397400">(Feb 12 2019 at 23:23)</a>:</h4>
<p>To take a particular example, I do not think anything in the vicinity of "constant time code" will ever be achievable by any compilation pipeline that involves LLVM in any way.</p>



<a name="158397490"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/black_box%20dejavu/near/158397490" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/black_box.20dejavu.html#158397490">(Feb 12 2019 at 23:24)</a>:</h4>
<p>Not constant time code, but having some mental model of how LLVM sees <code>black_box</code> in  term of Rust operations (volatile reads/writes) would be useful when using it in benchmarks</p>



<a name="158397583"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/black_box%20dejavu/near/158397583" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Hanna Kruppe <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/black_box.20dejavu.html#158397583">(Feb 12 2019 at 23:26)</a>:</h4>
<p><em>Possibly</em>, but I doubt I personally would get much value from that, and I eat and breathe LLVM IR and LLVM passes. But more importantly, this can be a rustc-specific note, not "the spec".</p>



<a name="158423470"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/black_box%20dejavu/near/158423470" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/black_box.20dejavu.html#158423470">(Feb 13 2019 at 08:55)</a>:</h4>
<p>I wonder if we could try playing some trick, such as saying the Rust abstract machine has a "magic global" or so, and <code>black_box</code> writes a pointer there. Then, if stuff gets written to that global with atomic instructions, there could be another thread (or so?) that takes the data and manipulates it. We also have a simple syntactic condition making sure the "magic global" is never read by real Rust code, meaning we don't have to actually compile the instructions that manipulate this global to real code. But when considering whether an optimization is correct, we <em>do</em> allow the context (the unknown code surrounding the code we are optimizing) to read from this magic global.<br>
The concurrency part about this seems "wrong" somehow, though. maybe signal handlers are a better model? not sure.</p>



<a name="158428374"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/black_box%20dejavu/near/158428374" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Hanna Kruppe <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/black_box.20dejavu.html#158428374">(Feb 13 2019 at 10:16)</a>:</h4>
<p>For the shared memory thing cramertj described, something like that seems fine. But for benchmarks, generally the "real" accesses to the data will be neither atomic nor volatile, so other threads or signal handlers accessing the data would be UB and that possibility will be rightly disregarded by optimizations. (Plus, there's also the question of how to map whatever semantics we choose to LLVM IR.)</p>



<a name="158687906"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/black_box%20dejavu/near/158687906" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/black_box.20dejavu.html#158687906">(Feb 16 2019 at 10:08)</a>:</h4>
<p>I can't tell, was this thread before my "two primitives" comment?</p>



<a name="158687916"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/black_box%20dejavu/near/158687916" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/black_box.20dejavu.html#158687916">(Feb 16 2019 at 10:09)</a>:</h4>
<p>yeah</p>



<a name="158687918"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/black_box%20dejavu/near/158687918" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/black_box.20dejavu.html#158687918">(Feb 16 2019 at 10:09)</a>:</h4>
<p>though I dont see that fundamentally changing anything, TBH^^ it's still "magic", isn't it?</p>



<a name="158687964"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/black_box%20dejavu/near/158687964" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/black_box.20dejavu.html#158687964">(Feb 16 2019 at 10:10)</a>:</h4>
<p>IMO the nice thing is we can require the values to still be valid</p>



<a name="158687966"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/black_box%20dejavu/near/158687966" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/black_box.20dejavu.html#158687966">(Feb 16 2019 at 10:10)</a>:</h4>
<p>i.e. it should affect performance but we guarantee 0 UB avoidance</p>



<a name="158687971"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/black_box%20dejavu/near/158687971" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/black_box.20dejavu.html#158687971">(Feb 16 2019 at 10:11)</a>:</h4>
<p>could even noop them out if --test is not passed or something silly like that</p>



<a name="158687983"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/black_box%20dejavu/near/158687983" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/black_box.20dejavu.html#158687983">(Feb 16 2019 at 10:11)</a>:</h4>
<p>I guess it's still dubious in terms of accidentally supporting constant-time stuff?</p>



<a name="158688084"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/black_box%20dejavu/near/158688084" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/black_box.20dejavu.html#158688084">(Feb 16 2019 at 10:14)</a>:</h4>
<p><span class="user-mention" data-user-id="120791">@RalfJ</span> I guess my point was that it's tamer if <code>bench_input(mem::uninitialized())</code> will always error in miri</p>



<a name="158688101"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/black_box%20dejavu/near/158688101" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/black_box.20dejavu.html#158688101">(Feb 16 2019 at 10:15)</a>:</h4>
<p>and <code>bench_output</code> couldn't accidentally be used to assume a pointer may escape</p>



<a name="158688105"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/black_box%20dejavu/near/158688105" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/black_box.20dejavu.html#158688105">(Feb 16 2019 at 10:15)</a>:</h4>
<p>(not sure if we can tell LLVM about the latter limitation)</p>



<a name="158688150"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/black_box%20dejavu/near/158688150" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/black_box.20dejavu.html#158688150">(Feb 16 2019 at 10:16)</a>:</h4>
<p>I kind of like the closure form but idk if we can spec it any better</p>



<a name="158688328"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/black_box%20dejavu/near/158688328" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/black_box.20dejavu.html#158688328">(Feb 16 2019 at 10:22)</a>:</h4>
<p><span class="user-mention" data-user-id="120791">@RalfJ</span> now I am tempted to do something silly like <code>x ^ bench_obscured_zero()</code> to replace <code>bench_input(x)</code>, especially since I suspect it's almost always integers, but I don't want to actually generate the <code>xor</code> instruction. if <code>x</code> is undef/poison I suspect this will propagate to the <code>xor</code></p>



<a name="158688338"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/black_box%20dejavu/near/158688338" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/black_box.20dejavu.html#158688338">(Feb 16 2019 at 10:23)</a>:</h4>
<p>defining the semantics of these functions is frustrating since they're "just" optimizer hints</p>



<a name="158688383"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/black_box%20dejavu/near/158688383" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/black_box.20dejavu.html#158688383">(Feb 16 2019 at 10:24)</a>:</h4>
<p>uhhhh</p>



<a name="158688386"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/black_box%20dejavu/near/158688386" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/black_box.20dejavu.html#158688386">(Feb 16 2019 at 10:24)</a>:</h4>
<p>you could just as well have an attribute on the bench closure to make its args obscured and return preserved, while allowing inlining</p>



<a name="158688425"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/black_box%20dejavu/near/158688425" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/black_box.20dejavu.html#158688425">(Feb 16 2019 at 10:24)</a>:</h4>
<p>if you want constant time code you write assembly, there’s currently no other way around it</p>



<a name="158688431"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/black_box%20dejavu/near/158688431" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/black_box.20dejavu.html#158688431">(Feb 16 2019 at 10:24)</a>:</h4>
<p>and definitely no way around it if your code goes through llvm</p>



<a name="158688434"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/black_box%20dejavu/near/158688434" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/black_box.20dejavu.html#158688434">(Feb 16 2019 at 10:24)</a>:</h4>
<p>yeah my point is I don't want to mix bench stuff with freeze or ct-time</p>



<a name="158688436"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/black_box%20dejavu/near/158688436" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/black_box.20dejavu.html#158688436">(Feb 16 2019 at 10:24)</a>:</h4>
<p>the bench stuff should be implementable as noops</p>



<a name="158688442"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/black_box%20dejavu/near/158688442" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/black_box.20dejavu.html#158688442">(Feb 16 2019 at 10:25)</a>:</h4>
<p>+</p>



<a name="158688447"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/black_box%20dejavu/near/158688447" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/black_box.20dejavu.html#158688447">(Feb 16 2019 at 10:25)</a>:</h4>
<p><code>#[inline(bench)]</code> lol</p>



<a name="158688495"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/black_box%20dejavu/near/158688495" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/black_box.20dejavu.html#158688495">(Feb 16 2019 at 10:26)</a>:</h4>
<p><code>#[inline(obscure)]</code> might be better, idk. basically <code>#[inline(always)]</code> plus obscured args and used return value</p>



<a name="158688935"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/black_box%20dejavu/near/158688935" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/black_box.20dejavu.html#158688935">(Feb 16 2019 at 10:41)</a>:</h4>
<blockquote>
<p>i.e. it should affect performance but we guarantee 0 UB avoidance</p>
</blockquote>
<p>wait but that's what the RFC already says, right?</p>



<a name="158688979"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/black_box%20dejavu/near/158688979" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/black_box.20dejavu.html#158688979">(Feb 16 2019 at 10:42)</a>:</h4>
<p>as far as I am concerned, specifying the "bench" part is pretty much solved, the RFC seems to do that fine</p>



<a name="158688980"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/black_box%20dejavu/near/158688980" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/black_box.20dejavu.html#158688980">(Feb 16 2019 at 10:42)</a>:</h4>
<p>some people don't like the name, is all</p>



<a name="158688994"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/black_box%20dejavu/near/158688994" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/black_box.20dejavu.html#158688994">(Feb 16 2019 at 10:42)</a>:</h4>
<p>but then the hard open question is how to specify the "UB-avoidance" stuff</p>



<a name="158689109"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/black_box%20dejavu/near/158689109" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/black_box.20dejavu.html#158689109">(Feb 16 2019 at 10:46)</a>:</h4>
<p>yeah it's just that some people have suggested renaming to <code>bench_used</code> but that only makes sense for bench outputs, not inputs</p>



<a name="158689123"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/black_box%20dejavu/near/158689123" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/black_box.20dejavu.html#158689123">(Feb 16 2019 at 10:47)</a>:</h4>
<p>if anyone thinks avoiding UB might be part of what a <code>black_box</code> is and will abuse it without reading the docs, we should probably use a different name</p>



<a name="158689127"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/black_box%20dejavu/near/158689127" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/black_box.20dejavu.html#158689127">(Feb 16 2019 at 10:47)</a>:</h4>
<p><code>black_box</code> is not a particularly helpful name anyway</p>



<a name="158690360"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/black_box%20dejavu/near/158690360" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/black_box.20dejavu.html#158690360">(Feb 16 2019 at 11:21)</a>:</h4>
<p><code>bench_obfuscate</code> :P</p>



<a name="158690510"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/black_box%20dejavu/near/158690510" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/black_box.20dejavu.html#158690510">(Feb 16 2019 at 11:24)</a>:</h4>
<p>that's good for inputs (and not far off my "obscure")</p>



<a name="158690533"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/black_box%20dejavu/near/158690533" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/black_box.20dejavu.html#158690533">(Feb 16 2019 at 11:25)</a>:</h4>
<p>I really want the input one to not keep the computation alive if it's unused and the output one to <em>only</em> do that keeping it alive thing</p>



<a name="158690539"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/black_box%20dejavu/near/158690539" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/black_box.20dejavu.html#158690539">(Feb 16 2019 at 11:25)</a>:</h4>
<p>but it seems hard to do in LLVM exactly like that</p>



<a name="158690907"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/black_box%20dejavu/near/158690907" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/black_box.20dejavu.html#158690907">(Feb 16 2019 at 11:33)</a>:</h4>
<p>I agree it makes sense to distinguish these two from a "spec" perspective ("spec" as in "compiler hint spec", not language spec)</p>



<a name="158690987"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/black_box%20dejavu/near/158690987" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/black_box.20dejavu.html#158690987">(Feb 16 2019 at 11:34)</a>:</h4>
<p>and I agree the bench harness should incorporate that:</p>
<div class="codehilite"><pre><span></span>bench::iter(inputs, |inputs| {
  let out = do_something_with(inputs);
  out
})
</pre></div>


<p>should pass inputs and outputs through <code>black_box</code> (or through the two separate operations you suggested)</p>



<a name="158691301"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/black_box%20dejavu/near/158691301" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> maksimsco <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/black_box.20dejavu.html#158691301">(Feb 16 2019 at 11:40)</a>:</h4>
<p>Is <code>pretend_use</code> far off?</p>



<a name="158691414"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/black_box%20dejavu/near/158691414" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/black_box.20dejavu.html#158691414">(Feb 16 2019 at 11:43)</a>:</h4>
<p>sounds okay for the output half</p>



<a name="158691476"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/black_box%20dejavu/near/158691476" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/black_box.20dejavu.html#158691476">(Feb 16 2019 at 11:44)</a>:</h4>
<p>but the current <code>black_box</code> is a weird "pretend the value escapes and can also be modified" all-in-one thing hence me suggesting to split it up</p>



<a name="158692014"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/black_box%20dejavu/near/158692014" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/black_box.20dejavu.html#158692014">(Feb 16 2019 at 11:58)</a>:</h4>
<p>that might also make finding less contentious names easier</p>



<a name="158704390"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/black_box%20dejavu/near/158704390" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> centril <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/black_box.20dejavu.html#158704390">(Feb 16 2019 at 17:22)</a>:</h4>
<p><span class="user-mention" data-user-id="202336">@maksimsco</span>  <code>pretend_use</code> seems pretty good actually</p>



<a name="158705414"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/black_box%20dejavu/near/158705414" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> maksimsco <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/black_box.20dejavu.html#158705414">(Feb 16 2019 at 17:53)</a>:</h4>
<p><span class="user-mention" data-user-id="126931">@centril</span> In my humble opinion anything other than <code>black_box</code> would be a path in a right direction, <code>black_box</code> is very misleading name IMO until you look in the code</p>



<a name="158705469"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/black_box%20dejavu/near/158705469" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> centril <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/black_box.20dejavu.html#158705469">(Feb 16 2019 at 17:54)</a>:</h4>
<p><span class="user-mention" data-user-id="202336">@maksimsco</span>  I mostly just want to ship the thing :P</p>



<a name="158705485"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/black_box%20dejavu/near/158705485" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> maksimsco <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/black_box.20dejavu.html#158705485">(Feb 16 2019 at 17:55)</a>:</h4>
<p>It's a good thing :)</p>



<a name="159188179"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/black_box%20dejavu/near/159188179" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/black_box.20dejavu.html#159188179">(Feb 22 2019 at 20:28)</a>:</h4>
<p><span class="user-mention" data-user-id="120791">@RalfJ</span> when using <code>asm!</code> you can either say, this reads this register and uses it, or you can also say this reads the memory behind this pointer</p>



<a name="159188216"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/black_box%20dejavu/near/159188216" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/black_box.20dejavu.html#159188216">(Feb 22 2019 at 20:28)</a>:</h4>
<p><code>"*m"(&amp;x)</code> states that this reads the memory behind the pointer <code>&amp;x</code>, which is just x</p>



<a name="159188249"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/black_box%20dejavu/near/159188249" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/black_box.20dejavu.html#159188249">(Feb 22 2019 at 20:29)</a>:</h4>
<p>if you want to state that the block also reads other memory, either you manually pass that as inputs to the block, or you can say <code>clobber "memory"</code></p>



<a name="159188273"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/black_box%20dejavu/near/159188273" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/black_box.20dejavu.html#159188273">(Feb 22 2019 at 20:29)</a>:</h4>
<p>which means that all memory is read by the assembly block, and/or written to</p>



<a name="159188335"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/black_box%20dejavu/near/159188335" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/black_box.20dejavu.html#159188335">(Feb 22 2019 at 20:30)</a>:</h4>
<p>that's globals, memory reachable by pointers, etc. private locals that the block cannot know anything about, aren't affected by it</p>



<a name="159188351"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/black_box%20dejavu/near/159188351" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/black_box.20dejavu.html#159188351">(Feb 22 2019 at 20:30)</a>:</h4>
<p>and that's pretty much all the tools we have with <code>asm!</code></p>



<a name="159188422"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/black_box%20dejavu/near/159188422" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/black_box.20dejavu.html#159188422">(Feb 22 2019 at 20:31)</a>:</h4>
<p>if you wanted to say, reads the memory behind some pointer, and all the memory behind all the pointers that might be there, you basically have to write <code>asm!("" : : "*m"(&amp;x), "*m(x.0)", ....)</code> somehow (where <code>x.0</code> is a ptr)</p>



<a name="159188541"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/black_box%20dejavu/near/159188541" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/black_box.20dejavu.html#159188541">(Feb 22 2019 at 20:32)</a>:</h4>
<p>for the Vec case, the pointer is of type <code>*mut T</code> and there are <code>len</code> elements behind it, so we somehow would need to generate a block that reads the memory of each of those <code>T</code>, from the knowledge that this is encoded in <code>len</code></p>



<a name="159188673"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/black_box%20dejavu/near/159188673" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/black_box.20dejavu.html#159188673">(Feb 22 2019 at 20:34)</a>:</h4>
<p>so iff we had a way to finding all memory reachable from a pointer, then we could do this with <code>asm!</code> or other tools, but AFAICT we do not have a way of finding that out</p>



<a name="159189131"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/black_box%20dejavu/near/159189131" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/black_box.20dejavu.html#159189131">(Feb 22 2019 at 20:41)</a>:</h4>
<p>hm okay, they are more limited than I thought then</p>



<a name="159189143"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/black_box%20dejavu/near/159189143" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/black_box.20dejavu.html#159189143">(Feb 22 2019 at 20:41)</a>:</h4>
<p>I'd have expected something like a "read-only <code>clobber</code>" -- can read anything, but write nothing</p>



<a name="159189191"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/black_box%20dejavu/near/159189191" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/black_box.20dejavu.html#159189191">(Feb 22 2019 at 20:42)</a>:</h4>
<p>(well, write whatever registers it gets assigned as writeable, but not anything else)</p>



<a name="159193771"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/black_box%20dejavu/near/159193771" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/black_box.20dejavu.html#159193771">(Feb 22 2019 at 21:42)</a>:</h4>
<p>yeah, that would be cool</p>



<a name="159193790"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/black_box%20dejavu/near/159193790" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/black_box.20dejavu.html#159193790">(Feb 22 2019 at 21:43)</a>:</h4>
<p>we could use that in both bench_input and bench_output</p>



<a name="159193834"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/black_box%20dejavu/near/159193834" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/black_box.20dejavu.html#159193834">(Feb 22 2019 at 21:43)</a>:</h4>
<p>i'm tending to think that the best is to propose black_box as is, and that we can implement bench_input and bench_output behind a feature gate, and maybe some day stabilize those and implement black_box on top of them</p>



<a name="159193907"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/black_box%20dejavu/near/159193907" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/black_box.20dejavu.html#159193907">(Feb 22 2019 at 21:44)</a>:</h4>
<p>black_box still addresses the use case of "please don't remove my benchmark", and if someone needs something more finer grained than that, while bench_input / _output might be enough, chances are that they won't</p>



<a name="159193953"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/black_box%20dejavu/near/159193953" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/black_box.20dejavu.html#159193953">(Feb 22 2019 at 21:45)</a>:</h4>
<p>like, playing with all the asm! options, LLVM accepts many of them and documents their semantics, but everything is full of disclaimers stating things like "LLVM will assume the worst and clobber everything"</p>



<a name="159194040"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/black_box%20dejavu/near/159194040" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/black_box.20dejavu.html#159194040">(Feb 22 2019 at 21:46)</a>:</h4>
<p>reading the lang refs sounds more like things are barely implemented to make clang correct, but that all code around asm! blocks is unnecessarily pessimized atm</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>